package cn.hejiang.mamis.core.service.impl;

import java.util.List;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.hejiang.mamis.core.dto.PlatUserDTO;
import cn.hejiang.mamis.core.entity.PlatUser;
import cn.hejiang.mamis.core.mapper.PlatUserMapper;
import cn.hejiang.mamis.core.service.PlatUserService;

@Service
@CacheConfig(keyGenerator = "cacheKeyGenerator")
public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser> implements PlatUserService {
	@Cacheable(cacheNames = "PLAT_USER")
	public List<PlatUserDTO> getUserList(String sysId) {
		return this.getBaseMapper().getUserList(sysId);
	}

	@Cacheable(cacheNames = "PLAT_USER")
	public PlatUser getUserById(String id) {
		return this.getBaseMapper().getUserById(id);
	}

	@Cacheable(cacheNames = "PLAT_USER")
	public PlatUser getUserByLoginName(String loginName) {
		return this.getBaseMapper().getUserByLoginName(loginName);
	}

	@Cacheable(cacheNames = "PLAT_USER")
	public PlatUser getUserByEmail(String email) {
		return this.getBaseMapper().getUserByEmail(email);
	}

	@CacheEvict(cacheNames = { "PLAT_USER", "SYS_ROLE_USER", "SYS_USER_MENU" }, allEntries = true)
	public boolean save(PlatUser user) {
		return super.save(user);
	}

	@CacheEvict(cacheNames = { "PLAT_USER", "SYS_ROLE_USER", "SYS_USER_MENU" }, allEntries = true)
	public boolean update(PlatUser user, Wrapper<PlatUser> wrapper) {
		return super.update(user, wrapper);
	}

	@CacheEvict(cacheNames = { "PLAT_USER", "SYS_ROLE_USER", "SYS_USER_MENU" }, allEntries = true)
	public boolean updateById(PlatUser user) {
		return super.updateById(user);
	}
}
